package day2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: watermelon
 * Date: 2025-05-28
 * Time: 13:50
 */
interface device{
    public void takeon();
    public void takeoff();
}
class Mouse implements device{
    @Override
    public void takeon() {
        System.out.println("打开鼠标");
    }
    @Override
    public void takeoff() {
        System.out.println("关闭鼠标");
    }
    public void click()
    {
        System.out.println("点击鼠标");
    }
}
class Keyboard implements device{
    @Override
    public void takeon() {
        System.out.println("打开键盘");
    }

    @Override
    public void takeoff() {
        System.out.println("关闭键盘");
    }
    public void button(){
        System.out.println("按下键盘");
    }
}
class computer
{
    public void poweron()
    {
        System.out.println("打开电脑");
    }
    public void poweroff()
    {
        System.out.println("关闭电脑");
    }
    public void usecomputer(device dc)
    {
        dc.takeon();
        if(dc instanceof Mouse)
        {
            Mouse mouse=new Mouse();
            mouse.click();
        } else if (dc instanceof Keyboard) {
            Keyboard keyboard=new Keyboard();
            keyboard.button();
        }
        dc.takeoff();
    }
}
public class Extend {
    public static void main(String[] args) {
        computer dc=new computer();
        dc.poweron();
        dc.usecomputer(new Mouse());
        dc.usecomputer(new Keyboard());
        dc.poweroff();
    }
}

